package com.wg.wuge.tulin.jvm;

import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class FutureTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        Callable callable = new CallableImpl();
//        FutureTask<String> futureTask = new FutureTask<>(callable);
//        //注意下，这个地方还是需要使用线程，start才可以。
//        Thread thread = new Thread(futureTask);
//        thread.start();
//        String s = futureTask.get();
//        System.out.println(s);

        CompletableFuture future1 = CompletableFuture.runAsync(() -> {
            System.out.println("runAsync1");
        });
        CompletableFuture future2 = CompletableFuture.runAsync(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("runAsync2");
        });
        future1.runAfterEither(future2, () -> {
            System.out.println("runAfterEither");
        });
//        completableFuture.get();

    }

}

class CallableImpl implements Callable<String> {
    @Override
    public String call() throws Exception {
        return "null";
    }
}
